import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;


public class ReaderThread extends Thread {

	 String fileContents = null;

	 
	 @Override
	public void run() {
		 
//		System.out.println("New thread");
//		System.out.println("my name : "+Thread.currentThread());
		
//		for(int i=1;i<=10;i++) {
//			System.out.println("new = "+i);
//		}
		
		read();
		showOutput();

		
		System.out.println("new  thread finish");
	}

	 public void showOutput() {
		 System.out.println("file is" +fileContents);
	 }

	 public void read() {
			try {
				// read a file
				File file = new File("d:/vijay.txt");
				FileReader fr;
				fr = new FileReader(file);
				BufferedReader br = new BufferedReader(fr);

				// put the contents in to the fileContensts string
				fileContents = br.readLine();
				
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	 }
	

	public static void main(String[] args) {
		System.out.println("my name : "+Thread.currentThread());
		ReaderThread adobeReader = new ReaderThread();
		adobeReader.start();
		
//		for(int i=1;i<=10;i++) {
//			System.out.println("main = "+i);
//		}
		
		// he should wait till the new finsh the job
		try {
			adobeReader.join();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		ReaderThread thread2 = new ReaderThread();
		
		
		// prin the string fileContents in the main thread
		System.out.println("String in filecontents is : " +adobeReader.fileContents);
		
		System.out.println("main thread finish");
	}

}
